//////////////////////////////////////////////////
// glParticleEmitter.h
//
// Author: Tarik Belabbas et Adrien Hoffer
//////////////////////////////////////////////////

#ifndef GLPARTICLEEMITTER_H_
#define GLPARTICLEEMITTER_H_

#include <glm/glm.hpp>
#include <string>
#include <list>
#include "../scene/glSceneNode.h"
#include "../glStore.h"
#include "../glVertexBO.h"

class glTexture2D;
class glShaderProgram;

class glParticleEmitter
{
public:
	glParticleEmitter			();
	virtual ~glParticleEmitter	();

	void		initialize		();

	void		render			( unsigned int _dtTimeMs, unsigned int _timeMs );

	void		addTexture		( const char* _texturePath );

	void		setPosition		( const glm::vec3& _position )	{ m_position = _position; }
	void		setDirection	( const glm::vec3& _direction )	{ m_direction = _direction; }
	void		setNbParticles	( unsigned int _nbParticles )	{ m_nbParticles = _nbParticles; }

	void		setAdvectVS		( const char* _advectVS )	{ m_advectVS = _advectVS; }
	void		setRenderVS		( const char* _renderVS )	{ m_renderVS = _renderVS; }
	void		setRenderFS		( const char* _renderFS )	{ m_renderFS = _renderFS; }

	bool		isInitialized	()	const	{ return m_init; }

private:
	void		generateBuffers	();
	void		setupShaders	();

	// Shaders
	std::string			m_advectVS;
	std::string			m_renderVS;
	std::string			m_renderFS;

	glm::vec3			m_position;
	glm::vec3			m_direction;

	glStore< float >	m_positions;
	glStore< float >	m_lives;
	glStore< float >	m_velocities;

	glVertexBO			m_positionsVBO;
	glVertexBO			m_positionsVBO2;

	glVertexBO			m_velocitiesVBO;
	glVertexBO			m_velocitiesVBO2;

	glVertexBO			m_livesVBO;
	glVertexBO			m_livesVBO2;

	glShaderProgram*	m_advectProgram;
	glShaderProgram*	m_renderProgram;

	std::list< glTexture2D* > m_textures;
	unsigned int		m_nbParticles;

	bool				m_init;
};

#endif /* GLPARTICLEEMITTER_H_ */
